package com.example.yls.demoa;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

/**
 * Created by yls on 2018/11/26.
 */

public class StudbOpenHelper extends SQLiteOpenHelper {
    public StudbOpenHelper(Context context, String name,
                           SQLiteDatabase.CursorFactory factory,
                           int version) {
        super(context, name, factory, version);
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        Log.e("StudbOpenHelper", "onCreate");
        String sql = "create table student(stuno varchar(20)," +
                "name varchar(20),age int)";
        sqLiteDatabase.execSQL(sql);

    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) {
        if (oldVersion == 1 && newVersion == 2) {
            String sql = "alter table student add column phone varchar(20)";
            sqLiteDatabase.execSQL(sql);
        }
        if (oldVersion == 2 && newVersion == 3) {
            String sql = "create table score (stuno varchar(20),score int)";
            sqLiteDatabase.execSQL(sql);
        }
    }
}
